package cn.turing.firecontrol.server.task;

import cn.turing.firecontrol.server.feign.RabbitFeignWeiXin;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class RedisTask {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @Autowired
    private RabbitTemplate rabbitTemplate;

    private final String QUEUE_NAME = "rabbit";

    //五分钟运行一次
    @Scheduled(fixedRate = 300000)
    public void saveData() {
        stringRedisTemplate.keys("sensor:*");
        log.warn("定时任务5分钟");
        //使用rabbitMQ 进行发送
        rabbitTemplate.convertAndSend("tmc.open.demos", "hshsh");
    }


    // 调用微信接口
    @Autowired
    private RabbitFeignWeiXin rabbitFeignWeiXin;

    @RabbitListener(queues = "tmc.open.demos")
    public void accept1(@Payload String message, @Headers Map map, Channel channel) {

        System.err.println("_______________________");

        System.err.println(message);
        // 发送微信消息
      //  rabbitFeignWeiXin.push();
    }



}
